<template>
  <div id="root">
    <el-menu
      default-active="1-4-1"
      class="el-menu-vertical-demo"
      @open="handleOpen"
      @close="handleClose"
      :collapse="isCollapse"
      background-color="#545c64"
      text-color="#fff"
      active-text-color="#ffd04b"
    >
     <h3>{{this.$store.state.tab.isCollapse ? '后台': '通用后台管理系统'}}</h3>
      <el-menu-item  @click="clickMenu(item)" v-for="item in nochildren"  :key="item.path" :index="item.path +''">
       
        <i :class="'el-icon-' + item.icon"></i>
        <span slot="title">{{item.lable}}</span>
      </el-menu-item>

      <el-submenu v-for="item in haschlidren" :key="item.path" :index="item.path + ''">
        <template slot="title">
          <i :class="'el-icon-' +item.icon "></i>
          <span slot="title">{{item.lable}}</span>
        </template>
        <el-menu-item-group v-for="(son,sonindex) in item.children" :key="son.path">
          <el-menu-item @click="clickMenu(son)" :index="sonindex +''">{{son.lable}}</el-menu-item>
        </el-menu-item-group>
      </el-submenu>
    </el-menu>
  </div>
</template>

<style lang="less" scoped>
.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 200px;
  min-height: 400px;
}
.el-menu{
    height: 100%;
    border: none;
    h3{
        color: #fff;
        text-align:center;
        line-height: 48px;
        
    }
}
#root{
    height: 100%;
}
</style>

<script>
export default {
    computed:{
        nochildren(){
            return this.menu.filter(item=>!item.children)
      
        },
        haschlidren(){
            return this.menu.filter(item=>item.children)
        },
        isCollapse(){
            return this.$store.state.tab.isCollapse; 
        }
    },
  data() {
    return {
    
      menu: [
        {
          path: "/",
          name: "home",
          lable: "首页",
          icon: "s-home",
          url: "Home/home",
        },
        {
          path: "/mall",
          name: "mall",
          lable: "mall",
          icon: "video-play",
          url: "MallManage/MallManage",
        },
        {
          path: "/user",
          name: "user",
          lable: "user",
          icon: "user",
          url: "UserManage/UserManage",
        },
        {
          lable: "其他",
          icon: "location",
          url: "UserManage/UserManage",
          children: [
            {
              path: "/page1",
              name: "page1",
              lable: "user1",
              icon: "user",
              url: "UserManage/UserManage",
            },
            {
              path: "/page2",
              name: "page2",
              lable: "user2",
              icon: "user",
              url: "User2Manage/User2Manage",
            },
          ],
        },
      ],
    };
  },
  methods: {
    handleOpen(key, keyPath) {
 
    },
    handleClose(key, keyPath) {
    
    },
    clickMenu(item){
        this.$router.push({
            path:item.name
        });
        this.$store.commit('selectMeun',item)
    },
    
    
  },
};
</script>